import { defineStore } from 'pinia'
import { ref } from 'vue'
// eslint规范之后，我们导入的类型前面要加上type
import type { User } from '@/types/user'

export const useUserStore = defineStore(
  'user',
  () => {
    const user = ref<User>()
    // 保存用户信息
    const setUser = (payload: User) => {
      user.value = payload
    }
    // 删除用户信息
    const deleteUser = () => {
      user.value = undefined
    }
    return { user, setUser, deleteUser }
  },
  { persist: true }
)
